$def with (course,user_data,is_staff)

$#
$# This file is part of INGInious. See the LICENSE and the COPYRIGHTS files for
$# more information about the licensing of this file.
$#

$ is_admin = user_manager.has_admin_rights_on_course(course)
<form method="post">
    <table class="table">
        <thead class="table-borderless">
            <tr>
                $if is_staff:
                    <th>$:_("member")</th>
                $else:
                    <th>$:_("student")</th>
                <th>$:_("username")</th>
                <th>$:_("email address")</th>
                <th>$:_("# task tried")</th>
                <th>$:_("# task done")</th>
                <th>$:_("current grade")</th>
                <th>
                    <div class="btn-group btn-group-sm" role="group">
                        <a href="$get_homepath()/admin/${course.get_id()}/download?format=taskid%2Fusername" class="btn btn-danger"
                           title=$:_('"Download  all submissions"') data-toggle="tooltip" data-placement="bottom"><i class="fa fa-download"></i></a>
                        <a href="$get_homepath()/admin/${course.get_id()}/students?csv" class="btn btn-info"
                           title=$:_('"Download CSV"') data-toggle="tooltip" data-placement="bottom"><i class="fa fa-table"></i></a>
                        $if not is_staff and is_admin:
                            <button type="button" data-toggle="modal" data-username="all students" data-type="all" data-target="#remove_modal" class="btn btn-warning remove_user" title=$:_('"Unregister all"')><i class="fa fa-user-times"></i></button>
                    </div>
                </th>
            </tr>
        </thead>
        <tbody>
        $for user in user_data:
             <tr>
                <td>
                    $(user["realname"] or user["username"])
                </td>
                <td>
                    $user["username"]
                </td>
                <td>
                    <a href='mailto:$user["email"]'>$user["email"]</a>
                </td>
                <td>$user["task_tried"]</td>
                <td>$user["task_succeeded"]</td>
                <td>
                    <div class="progress">
                        <div class="progress-bar bg-success" role="progressbar" aria-valuenow="$user['grade']" aria-valuemin="0" aria-valuemax="100" style="width: $user['grade']%">
                            <span>$user["grade"]%</span>
                        </div>
                    </div>
                </td>
                <td>
                    <div class="btn-group btn-group-sm" role="group">
                        <a href="$get_homepath()/admin/${course.get_id()}/student/$user['username']" class="btn btn-secondary" title=$:_('"View submissions"')
                           data-toggle="tooltip" data-placement="bottom"><i class="fa fa-search"></i></a>
                        <a href="$get_homepath()/admin/${course.get_id()}/download$user['url']" class="btn btn-secondary" title=$:_('"Download submissions"')
                           data-toggle="tooltip" data-placement="bottom"><i class="fa fa-download"></i></a>
                        $if is_admin and not is_staff:
                            <a href="$get_homepath()/admin/${course.get_id()}/replay$user['url']" class="btn btn-secondary" title=$:_('"Replay submissions"')
                               data-toggle="tooltip" data-placement="bottom"><i class="fa fa-refresh"></i></a>
                            <button type="button" data-username="$user['username']" data-type="single" data-toggle="modal" data-target="#remove_modal" class="btn btn-warning remove_user" title="Unregister"><i class="fa fa-user-times"></i></button>
                    </div>
                </td>
            </tr>
        </tbody>
    </table>

    $if not is_staff:
        <div id="remove_modal" class="modal fade">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <h4 class="modal-title">$:_("Unregister") <span class="username"></span></h4>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    </div>
                    <div class="modal-body">
                        <p>$:_("This will remove {} from the course. Are you sure ?").format('<span class="username"></span>')</p>
                    </div>
                    <div class="modal-footer">
                        <input type="hidden" name="type" id="type">
                        <input type="hidden" name="username" id="username">
                        <button type="button" class="btn btn-default" data-dismiss="modal">$:_("Cancel")</button>
                        <button type="submit" name="remove" class="btn btn-danger">$:_("Remove {}").format('<span class="username"></span>')</button>
                    </div>
                </div>
            </div>
        </div>

        <script type="text/javascript">
            $$('#remove_modal').on('show.bs.modal', function (event) {
              $$('.modal-dialog .username').each(function (index) {
                  $$(this).text($$(event.relatedTarget).data('username'));
              });
              $$('.modal-dialog #username').val($$(event.relatedTarget).data('username'));
              $$('.modal-dialog #type').val($$(event.relatedTarget).data('type'));
            });
            $$(".remove_user").each(function(index) {
                $$(this).tooltip({"placement": "bottom"});
            });
        </script>

</form>
